import request from "./request";

export const cartService = {
  // 获取购物车列表
  async getCartList() {
    return await request({
      url: "Cart/list",
      method: "GET",
    });
  },

  // 添加到购物车
  async addToCart(data) {
    return await request({
      url: "Cart/add",
      method: "POST",
      data,
    });
  },

  // 更新购物车商品数量
  async updateCartQuantity(cartId, quantity) {
    console.log("准备发送更新请求:", {
      url: 'Cart/update',
      method: "PUT",
      data: { 
        cartId,
        quantity 
      }
    });

    const requestData = { 
      cartId,
      quantity 
    };
    console.log("请求体数据:", JSON.stringify(requestData));

    return await request({
      url: 'Cart/update',
      method: "PUT",
      data: requestData
    });
  },

  // 删除购物车商品
  async removeFromCart(skuId) {
    return await request({
      url: `Cart/delete/${skuId}`,
      method: "DELETE",
    });
  },

  // 清空购物车
  async clearCart() {
    return await request({
      url: "Cart/clear",
      method: "DELETE",
    });
  },
};
